<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css"
          href="Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="Css/style.css"/>
    <script type="text/javascript" src="Js/jquery.js"></script>
    <script type="text/javascript" src="Js/bootstrap.js"></script>
    <script type="text/javascript" src="Js/ckform.js"></script>
    <script type="text/javascript" src="Js/common.js"></script>
    <link href="layui/css/layui.css" rel="stylesheet"/>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media ( max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div id="levelMenu" style="width:300px;height:500px; border:1px solid black; margin:20px;"></div>
    <tr>
        <td>
            <input type="button" class="btn btn-info" value="提交" id="btn_getCk"/>
        </td>
        <td>
            <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
        </td>
    </tr>
</form>
</body>
</html>
<!--引入你自己的layui文件-->
<script src="layui/layui.js"></script>
<%--<!--xtree的js文件-->--%>
<%--<script src="assets/layui-xtree/layui-xtree.js"></script>--%>
<script type="text/javascript">
    $("#backid").click(function () {
        window.location.href = "/role/list";
    })
</script>

<script>
    // var menus="";
    // function getMenus(roleId){
    //     $.ajax({
    //         url: "/rolemenu/getMenuByRoleId?roleId="+roleId,
    //         type: "post",
    //         async: true,
    //         // data: param,
    //         success: function (res) {
    //             menus=res;
    //         }, error: function (e) {
    //             alert(e)
    //         }
    //     });
    // }

    $("#btn_getCk").click(function () {
        saveRoleMenu(${roleId})
    })


    var saveData = "";
    var tree;
    layui.use('tree', function () {
        tree = layui.tree;

        //渲染
        var inst1 = tree.render({
            elem: '#levelMenu',  //绑定元素
            showCheckbox: true,
            isJump: true,
            data: ${menus},
            id: "treeData"
        });
    });

    //保存修改
    function saveRoleMenu(roleId) {
        $.ajax({
            url: "/role/saveRoleMenu?roleId=" + roleId,
            type: "post",
            async: true,
            //contentType:"application/json",
            data: {"menus": JSON.stringify(tree.getChecked('treeData'))},
            success: function (res) {
                if (res.success) {
                    alert("修改成功");
                }
            }, error: function (e) {
                alert("修改失败");
            }
        });
    }
</script>